﻿// MovInstruction.cs
// Contains a class for a mov instruction

using System;


namespace armsim
{
    /// <summary>
    /// A 32 bit Mov Instruction in the Arm Architecture
    /// </summary>
    public class MovInstruction : DataProcessingInstruction 
    {
        
        /// <summary>
        /// Intializes a new MovInstruction
        /// </summary>
        /// <param name="instruction">instruction value to be decoded from</param>
        public MovInstruction(uint instruction)
            : base(instruction)
        {

        }

        /// <summary>
        /// Executes the Mov Instruction
        /// </summary>
        /// <param name="cpu">Executes from the cpu and stores the results in the cpu</param>
        public override void Execute(VirtualCPU cpu)
        {

            //var rn = cpu.Registers.ReadWord(Memory.MapRegNoToRegMem(this.Rn));
            var rm = this.Operand2.ComputeValue(cpu);
            cpu.Registers.WriteWord(VirtualMemory.MapRegNoToRegMem(this.Rd), (rm));
        }

        /// <summary>
        /// Converts the Mov instruction to assembly
        /// </summary>
        /// <param name="cpu">cpu to get information from</param>
        /// <returns>the assembly</returns>
        public override String ToAssembly(VirtualCPU cpu)
        {
            return String.Format("MOV {0}, {1}", VirtualMemory.RegToAssembly(Rd), this.Operand2.ToAssembly(cpu));
        }

    }
}
